cmake_minimum_required(VERSION 3.6)
project(CarControl)

# 设置 C++ 标准 - 使用 C++11 确保兼容性
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 编译选项
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -O2 -pthread")

# 定义 bin 目录路径（项目根目录下的 bin 文件夹）
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

# 查找依赖库
find_package(OpenCV REQUIRED)
find_package(Threads REQUIRED)

include_directories(

    ${CMAKE_SOURCE_DIR}/include  # 包含所有子目录（common/can/control/web）
    ${CMAKE_SOURCE_DIR}/src/WebServer
    ${CMAKE_SOURCE_DIR}/src/Camera
    PRIVATE ${OpenCV_INCLUDE_DIRS}
    ${YAML-CPP_INCLUDE_DIRS}
)

file(GLOB SOURCES
    ${CMAKE_SOURCE_DIR}/src/main.cpp 
    ${CMAKE_SOURCE_DIR}/src/CANBus.cpp  
    ${CMAKE_SOURCE_DIR}/src/Config.cpp 

    ${CMAKE_SOURCE_DIR}/src/MotorController.cpp 
    ${CMAKE_SOURCE_DIR}/src/Keyboard.cpp
    src/WebServer/*.cpp
    src/Camera/*.cpp
    
)

add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} 
    PRIVATE pthread
    PRIVATE ${OpenCV_LIBS}
    PRIVATE Threads::Threads
)


# 复制前端文件到输出目录（运行时可直接访问）
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
    ${CMAKE_SOURCE_DIR}/web
    $<TARGET_FILE_DIR:${PROJECT_NAME}>/web
)
